const gameObjects = [];

export class gameObject {
  constructor() {
    gameObjects.push(this);
    this.timeDelta = 0;
    this.hasStart = false;
  }

  start() {//初始化

  }
  update() {//每一帧执行一次

  }
  on_destroy() {//删除前执行

  }
  destroy() {
    for (let i in gameObjects) {
      const t = gameObjects[i];
      if (t == this) gameObjects.splice(i);
      break;
    }
  }
}
let last_timestamp;  // 上一次执行的时刻
const step = timestamp => {
  for (let obj of gameObjects) {
    if (!obj.hasStart) {
      obj.hasStart = true;
      obj.start();
    } else {
      obj.timedelta = timestamp - last_timestamp;
      obj.update();
    }
  }

  last_timestamp = timestamp;
  requestAnimationFrame(step)
}
requestAnimationFrame(step)
